#include "lstack.h"
#include <func.h>
void initializeStack(Lstack* stack) {
    stack->top = NULL;
    stack->size = 0;
}

int isEmpty(Lstack* stack) {
    return stack->top == NULL;
}

int getSize(Lstack* stack) {
    return stack->size;
}

void push(Lstack* stack, const char* value) {
    Lnode* newNode = (Lnode*)malloc(sizeof(Lnode));
    strcpy(newNode->data, value);
    newNode->next = stack->top;
    stack->top = newNode;
    stack->size++;
}

char* pop(Lstack* stack) {
    if (isEmpty(stack)) {
        printf("Stack is empty.\n");
        return NULL;
    }
    char* value = stack->top->data;
    Lnode* temp = stack->top;
    stack->top = stack->top->next;
    stack->size--;
    free(temp);
    return value;
}

char* peek(Lstack* stack) {
    if (isEmpty(stack)) {
        printf("Stack is empty.\n");
        return NULL;
    }
    return stack->top->data;
}
